/*
 * Created on 8 juin 2007
 */
package fr.mywiki.view.web.struts.form.version;

import java.util.List;

import org.apache.struts.action.ActionForm;

import fr.mywiki.business.entry.EntryLite;
import fr.mywiki.business.utils.CollectUtils;
import fr.mywiki.business.versioning.VersionManager;

/** Form dealing with the display of a list of versions */
public class VersionListForm extends ActionForm {
	private static final long serialVersionUID = 1L;

	/** The displayed list of versions */
	private List versionList;
	
	/** The selected version's identifier */
	private String versionId;
	
	/** The version identifier which would be on the <tt>from</tt> side of the version comparison */
	private String from;
	
	/** The version identifier which would be on the <tt>to</tt> side of the version comparison */
	private String to;

	/**
	 * Loads and returns the list of versions for the entry given in parameter.
	 * 
	 * @param entry a <code>EntryLite</code> object.
	 * @return a <code>List</code> of <code>VersionLite</code> objects.
	 */
	public void initVersionsList(EntryLite entry) {
		List versions = VersionManager.getInstance().getVersions(entry);
		versionList = CollectUtils.invert(versions);
		
		to = entry.getCurrentVersion().toString();
		from = null;
	}
	
	public List getVersionList() {
		return versionList;
	}

	public void setVersionList(List versionList) {
		this.versionList = versionList;
	}

	public String getVersionId() {
		return versionId;
	}

	public void setVersionId(String versionId) {
		this.versionId = versionId;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}
}
